<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>添加老师</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/layuiadmin/layui/css/layui.css" media="all">
</head>
<body >
<div class="layui-form" lay-filter="layuiadmin-form-user" id="layuiadmin-form-user" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <select name="roleId" id="roleId">
                <c:forEach var="role" items="${roles}">
                    <option value="${role.id}">${role.name}</option>
                </c:forEach>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" id="nickName"  name="nickName"  placeholder="请输入员工姓名"  class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" id="userName"  name="userName"   placeholder="请输入用户名"  class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">email</label>
        <div class="layui-input-inline">
            <input type="text" id="email" name="email" placeholder="请输入邮箱"  class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="text" id="phone" name="phone" placeholder="请输入手机号"   class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked>
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">出生日期</label>
        <div class="layui-input-inline">
            <input type="text" name="birthday" id="birthday"  placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" id="pp" placeholder="请输入密码"  class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input type="password" id="twopwd"  name="twopwd"  placeholder="请输入确认密码"  class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="LAY-user-role-submit" id="subBtn">提交</button>
        </div>
    </div>
</div>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    var $;
    layui.use(['layer', 'form','element','jquery'], function(){
        var layer = layui.layer,
            form = layui.form;
            $ = layui.jquery;
            element = layui.element;

        //监听提交
        form.on('submit(LAY-user-role-submit)', function(data){

            var role=$('#role').val();
            var nickName=$('#nickName').val();
            if(nickName==''||nickName==null){ layer.msg("请输入姓名"); return false;  }

            var userName=$('#userName').val();
            if(userName==''||userName==null){ layer.msg("请输入用户名"); return false; }

            var pwd=$('#pp').val();
            if(pwd==''||pwd==null){ layer.msg("请输入登陆密码"); return false; }
            var twopwd=$('#twopwd').val();
            if(pwd != twopwd){ layer.msg("两次密码不一致"); return false;}
            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/user/add",
                // data: {"rid":role,"name":userName,"nickName":nickName,"pwd":pwd},
                data: JSON.stringify(data.field),
                dataType: "json",
                contentType: "application/json",
                success: function (date) {
                    if(date==-1){
                        layer.msg("用户名重复!");
                    }else if(date==0){
                        layer.msg("添加成功");
                        var index=parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    }else{
                        layer.msg("添加失败，请稍后重试！");

                    }

                }
            });
        });


        <%--$('#subBtn').click(function () {--%>
        <%--    var role=$('#role').val();--%>
        <%--    //操作权限--%>
        <%--    var operate="";--%>
        <%--    $.each($("input[name='operate']"),function(){--%>
        <%--        if(this.checked){--%>
        <%--            operate+=$(this).val()+",";--%>
        <%--        }--%>
        <%--    });--%>
        <%--    var nickName=$('#nickName').val();--%>
        <%--    if(nickName==''||nickName==null){ layer.msg("请输入姓名"); return false;  }--%>

        <%--    var userName=$('#userName').val();--%>
        <%--    if(userName==''||userName==null){ layer.msg("请输入用户名"); return false; }--%>

        <%--    var pwd=$('#pp').val();--%>
        <%--    if(pwd==''||pwd==null){ layer.msg("请输入登陆密码"); return false; }--%>
        <%--    var twopwd=$('#twopwd').val();--%>
        <%--    if(pwd != twopwd){ layer.msg("两次密码不一致"); return false;}--%>
        <%--    $.ajax({--%>
        <%--        type: "post",--%>
        <%--        url: "<%=request.getContextPath()%>/user/add",--%>
        <%--        data: {"rid":role,"name":userName,"nickName":nickName,"pwd":pwd,"operate":operate},--%>
        <%--        dataType: "json",--%>
        <%--        success: function (date) {--%>
        <%--            if(date==-1){--%>
        <%--                layer.msg("用户名重复!");--%>
        <%--            }else if(date==0){--%>
        <%--                layer.msg("添加成功");--%>
        <%--                var index=parent.layer.getFrameIndex(window.name);--%>
        <%--                parent.layer.close(index);--%>
        <%--                parent.location.reload();--%>
        <%--            }else{--%>
        <%--                layer.msg("添加失败，请稍后重试！");--%>

        <%--            }--%>

        <%--        }--%>
        <%--    });--%>
        <%--    });--%>
    });
</script>
</body>
</html>
